package com.fz;

import com.fz.entity.Student;
import com.fz.mapper.StudentMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.util.List;

/**
 * Created by webrx on 2017-08-23.
 */
public class Demo {
    public static void main(String[] args) {
        try {
            SqlSessionFactory sf = new SqlSessionFactoryBuilder().build(Resources.getResourceAsReader("mybatis-config.xml"));
            SqlSession s = sf.openSession();
            StudentMapper sdao = s.getMapper(StudentMapper.class);
            //int i = sdao.deleteById(4);
            //System.out.println(i);

            //Student sss = sdao.queryById(3);
            //sss.setScore(100);
            //sss.setName("李晓丽");
            //sss.setAddress("上海市某某区");
            //sdao.update(sss);

            sdao.delete();

            List<Student> ss = sdao.query();
            for(Student st : ss){
                System.out.println(st.getName());
            }

            s.commit();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
